"use strict";
const way = require("../utils/way");

/**
 * 发券
 * @param {*} cloud 
 * @param {*} openId 
 * @param {*} code 
 * @param {*} miniAppId 
 */
exports.send = async (cloud, openId, code, miniAppId) => {
  const unique_id = new Date().getTime();
  const data = {
    'right_ename': code,
    'receiver_id': openId,
    'user_type': 'taobao',
    'unique_id': unique_id,
    'app_name': "promotioncenter-" + miniAppId
  };
  return await way.taobao(cloud, "alibaba.benefit.send", data);
};

/**
 * 专属下单绑定
 * @param {*} cloud 
 * @param {*} item_id 
 */
exports.bind = async (cloud, item_id) => {
  cloud.topApi.client.appkey = '34493428';
  cloud.topApi.client.appsecret = '33ebd8267e8f714f76d3d8667e84fa5d';
  let data = {
    'session': '50000800918t1kiHiyR4OQE9djuCIQ189e42b0hSTlddcPenxYEIGxiYmujiDe3tc2ns',
    'item_ids': item_id,
    'miniapp_id': 3000000095157911
  };
  console.log("bind data", data);
  const res = await way.taobaoInvoke(cloud, "taobao.opentrade.special.items.bind", data);
  console.log("bind results", res);
  return res;
};

/**
 * 专属下单绑定
 * @param {*} cloud 
 * @param {*} item_id 
 */
exports.unbind = async (cloud, item_id) => {
  cloud.topApi.client.appkey = '34493428';
  cloud.topApi.client.appsecret = '33ebd8267e8f714f76d3d8667e84fa5d';
  let data = {
    'session': '50000800918t1kiHiyR4OQE9djuCIQ189e42b0hSTlddcPenxYEIGxiYmujiDe3tc2ns',
    'item_ids': item_id,
    'miniapp_id': 3000000095157911
  };
  console.log("bind data", data);
  const res = await way.taobaoInvoke(cloud, "taobao.opentrade.special.items.unbind", data);
  console.log("bind results", res);
  return res;
};
